/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 combat_castle.h

	$Header: /heroes4/combat_castle.h $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )


#include "combat_castle.h"

#include "strip_resource_name.h"

char const t_resource_traits< t_combat_castle >::prefix[] = "castle";

char const t_resource_traits< t_combat_castle >::extension[] = "cst";

int const k_version = 1;

// -------------------------------------------------------------
// combat castle
// -------------------------------------------------------------
bool t_combat_castle::read( std::streambuf& stream )
{
	int count;
	int i;
	int version;

	version = get<t_uint8>( stream );
	if (version > k_version)
		return false;
	m_objects.clear();
	count = get<t_uint16>(stream);
	m_objects.resize( count );
	for (i = 0; i < count; i++)
	{
		t_combat_castle_item& item = m_objects[i];

		read_string16( stream, item.name );
		if (version == 0)
			item.name = strip_type_and_extension( item.name );
		::read( stream, &item.position, sizeof( item.position ));
	}
	return true;
}

// -------------------------------------------------------------
// combat castle
// -------------------------------------------------------------
bool t_combat_castle::write( std::streambuf& stream) const
{
	int i;

	put<t_uint8>( stream, k_version );
	put<t_uint16>( stream, m_objects.size() );
	for (i = 0; i < m_objects.size(); i++)
	{
		write_string16( stream, m_objects[i].name );
		::write( stream, &m_objects[i].position, sizeof( m_objects[i].position ));
	}
	return true;
}


